home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / ms-cardr.c / ms-cardr
Text File  |  1993-03-01  |  3KB  |  113 lines

  1. Article 28977 of comp.os.linux:
  2. Path: samba!concert!gatech!howland.reston.ans.net!spool.mu.edu!uunet!news.claremont.edu!nntp-server.caltech.edu!thefru
  3. From: thefru@cco.caltech.edu (Your Worst Nightmare)
  4. Newsgroups: comp.os.linux
  5. Subject: MS-Cardfile Reader for Linux
  6. Date: 1 Mar 1993 17:30:14 GMT
  7. Organization: California Institute of Technology, Pasadena
  8. Lines: 99
  9. Message-ID: <1mth76INN54b@gap.caltech.edu>
  10. NNTP-Posting-Host: punisher.caltech.edu
  11.  
  12. Hi all!
  13.  
  14. I don't know if this is the right group to put this on or if c.o.l.a is since I
  15. don't nn too often.  I found out a long time ago that it's harmful for my GPA.
  16.  
  17. I also don't know how many of you out there share my situation, but I'm an avid
  18. MS-Windows user.  Mostly for the sake of writing papers, spreadsheets etc.
  19. While linux serves as my programming environment (and a superb one at that.)
  20.  
  21. The problem I had was that I couldn't access my cardfile data from linux, so I
  22. wrote a little program that does it and prints it out to stdout.  The format is
  23. so trivial!  I'm not sure if dosemu can do MS-Win yet, since I haven't
  24. installed it.  If it can, this is a moot point.  If it can't - enjoy!
  25.  
  26. Oh yeah, one last thing.  This program is really rough and is mostly one big
  27. hack (hehe).  I envision, one day, an x-app that will simulate cardfile, so you
  28. can also add stuff in.  Again, the usefulness may be nil if dosemu runs it
  29. well, but hey, I'll look into that some other morning when I haven't slept for
  30. two days... ;)
  31.  
  32. Allright - here's the source code for cardread.c:
  33.  
  34. /* CardRead V1.0
  35.  * A program that will read and print out Microsoft Cardfile files.
  36.  * By Dan 'Fru' Frumin
  37.  * March 1st, 1993
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include <strings.h>
  42.  
  43. typedef struct {
  44.   char name[46];
  45.   char data[1000];
  46.   } INFO;
  47.  
  48. main(int argc, char **argv) {
  49.   FILE *fp;
  50.   char buf[81];
  51.   INFO *data;
  52.   int reccount, counter, len;
  53.   char c;
  54.   int i;
  55.  
  56.   if (argc != 2) {
  57.     printf("Usage: %s file\n", argv[0]);
  58.     exit(-1);
  59.     }
  60.  
  61.   fp = fopen(argv[1], "r");
  62.   if (!fp) {
  63.     printf("Error: %s couldn't open %s.\n", argv[0], argv[1]);
  64.     exit(-1);
  65.     }
  66.  
  67.   fgets(buf, 4, fp);
  68.   if (strcmp(buf,"MGC")) {
  69.     printf("Error: %s isn't in Microsoft Cardfile format.\n", argv[1]);
  70.     exit(-1);
  71.     }
  72.  
  73.   reccount = fgetc(fp);
  74.   data = (INFO *) malloc (reccount * sizeof(INFO));
  75.  
  76.   for (i = 0; i < 12; i++, fgetc(fp));
  77.  
  78.   for (counter = 0; counter < reccount; counter++) {
  79.     fgets(data[counter].name, 46, fp);
  80.     if (data[counter].name[0] == 0)
  81.       sprintf(data[counter].name, "NULL");
  82.     if (counter < reccount - 1)
  83.       for (i = 0; i < 7; i++, fgetc(fp));
  84.     }
  85.  
  86.   counter = 0;
  87.   i = 0;
  88.   while((c = fgetc(fp)) != EOF) {
  89.     data[counter].data[i] = c;
  90.     i++;
  91.     if (c == 0) {
  92.       for (i = 0; i < 3; i++, fgetc(fp));
  93.       counter++;
  94.       i=0;
  95.       }
  96.     }
  97.  
  98.   fclose(fp);
  99.  
  100.   printf("=============================================\n");
  101.   for (counter = 0; counter < reccount; counter++) {
  102.     printf("%s\n", data[counter].name);
  103.     printf("---------------------------------------------\n");
  104.     printf("%s\n", data[counter].data);
  105.     printf("\n");
  106.     printf("=============================================\n");
  107.     }
  108.   }
  109.  
  110.  
  111.  
  112.  
  113.